{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "babd7f43",
   "metadata": {},
   "source": [
    "* week03笔记补充\n",
    "* 2023-10-30\n",
    "* python课程"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43851869",
   "metadata": {},
   "source": [
    "# 模块\n",
    ">  1.标准库 \n",
    ">\n",
    ">  2.开源模块 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ad24f87",
   "metadata": {},
   "source": [
    "### 1.标准库[函数+模块=标准库】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c7497647",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys #import是函数，sys是模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "91865123",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'win32'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sys.platform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4b9f45a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3.11.4 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 13:38:37) [MSC v.1916 64 bit (AMD64)]'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sys.version"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d4d659f",
   "metadata": {},
   "source": [
    "### 2.开源模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29ed2b3d",
   "metadata": {},
   "source": [
    "* 安装模块的方法\n",
    "> pip install module_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b41495cf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pyecharts in d:\\anaconda3\\lib\\site-packages (2.0.4)\n",
      "Requirement already satisfied: jinja2 in d:\\anaconda3\\lib\\site-packages (from pyecharts) (3.1.2)\n",
      "Requirement already satisfied: prettytable in d:\\anaconda3\\lib\\site-packages (from pyecharts) (3.9.0)\n",
      "Requirement already satisfied: simplejson in d:\\anaconda3\\lib\\site-packages (from pyecharts) (3.19.2)\n",
      "Requirement already satisfied: MarkupSafe>=2.0 in d:\\anaconda3\\lib\\site-packages (from jinja2->pyecharts) (2.1.1)\n",
      "Requirement already satisfied: wcwidth in d:\\anaconda3\\lib\\site-packages (from prettytable->pyecharts) (0.2.5)\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3b09f45a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4c6be5a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "253479a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "environ{'ALLUSERSPROFILE': 'C:\\\\ProgramData',\n",
       "        'APPDATA': 'C:\\\\Users\\\\qiqi Yu\\\\AppData\\\\Roaming',\n",
       "        'COMMONPROGRAMFILES': 'C:\\\\Program Files\\\\Common Files',\n",
       "        'COMMONPROGRAMFILES(X86)': 'C:\\\\Program Files (x86)\\\\Common Files',\n",
       "        'COMMONPROGRAMW6432': 'C:\\\\Program Files\\\\Common Files',\n",
       "        'COMPUTERNAME': 'LAPTOP-R0KE5A82',\n",
       "        'COMSPEC': 'C:\\\\Windows\\\\system32\\\\cmd.exe',\n",
       "        'DRIVERDATA': 'C:\\\\Windows\\\\System32\\\\Drivers\\\\DriverData',\n",
       "        'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer',\n",
       "        'FPS_BROWSER_USER_PROFILE_STRING': 'Default',\n",
       "        'HOMEDRIVE': 'C:',\n",
       "        'HOMEPATH': '\\\\Users\\\\qiqi Yu',\n",
       "        'LOCALAPPDATA': 'C:\\\\Users\\\\qiqi Yu\\\\AppData\\\\Local',\n",
       "        'LOGONSERVER': '\\\\\\\\LAPTOP-R0KE5A82',\n",
       "        'NUMBER_OF_PROCESSORS': '20',\n",
       "        'ONEDRIVE': 'C:\\\\Users\\\\qiqi Yu\\\\OneDrive',\n",
       "        'OS': 'Windows_NT',\n",
       "        'PATH': 'C:\\\\Windows\\\\system32;C:\\\\Windows;C:\\\\Windows\\\\System32\\\\Wbem;C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\;C:\\\\Windows\\\\System32\\\\OpenSSH\\\\;C:\\\\Program Files (x86)\\\\NVIDIA Corporation\\\\PhysX\\\\Common;C:\\\\Program Files\\\\NVIDIA Corporation\\\\NVIDIA NvDLISR;D:\\\\微信web开发者工具\\\\dll;D:\\\\anaconda3;D:\\\\anaconda3\\\\Library\\\\mingw-w64\\\\bin;D:\\\\anaconda3\\\\Library\\\\usr\\\\bin;D:\\\\anaconda3\\\\Library\\\\bin;D:\\\\anaconda3\\\\Scripts;C:\\\\Users\\\\qiqi Yu\\\\AppData\\\\Local\\\\Microsoft\\\\WindowsApps',\n",
       "        'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',\n",
       "        'PROCESSOR_ARCHITECTURE': 'AMD64',\n",
       "        'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 154 Stepping 3, GenuineIntel',\n",
       "        'PROCESSOR_LEVEL': '6',\n",
       "        'PROCESSOR_REVISION': '9a03',\n",
       "        'PROGRAMDATA': 'C:\\\\ProgramData',\n",
       "        'PROGRAMFILES': 'C:\\\\Program Files',\n",
       "        'PROGRAMFILES(X86)': 'C:\\\\Program Files (x86)',\n",
       "        'PROGRAMW6432': 'C:\\\\Program Files',\n",
       "        'PROMPT': '$P$G',\n",
       "        'PSMODULEPATH': 'C:\\\\Program Files\\\\WindowsPowerShell\\\\Modules;C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\Modules',\n",
       "        'PUBLIC': 'C:\\\\Users\\\\Public',\n",
       "        'SESSIONNAME': 'Console',\n",
       "        'SYSTEMDRIVE': 'C:',\n",
       "        'SYSTEMROOT': 'C:\\\\Windows',\n",
       "        'TEMP': 'C:\\\\Users\\\\QIQIYU~1\\\\AppData\\\\Local\\\\Temp',\n",
       "        'TMP': 'C:\\\\Users\\\\QIQIYU~1\\\\AppData\\\\Local\\\\Temp',\n",
       "        'USERDOMAIN': 'LAPTOP-R0KE5A82',\n",
       "        'USERDOMAIN_ROAMINGPROFILE': 'LAPTOP-R0KE5A82',\n",
       "        'USERNAME': 'qiqi Yu',\n",
       "        'USERPROFILE': 'C:\\\\Users\\\\qiqi Yu',\n",
       "        'WINDIR': 'C:\\\\Windows',\n",
       "        'ZES_ENABLE_SYSMAN': '1',\n",
       "        'PYDEVD_USE_FRAME_EVAL': 'NO',\n",
       "        'JPY_INTERRUPT_EVENT': '4180',\n",
       "        'IPY_INTERRUPT_EVENT': '4180',\n",
       "        'JPY_PARENT_PID': '4276',\n",
       "        'TERM': 'xterm-color',\n",
       "        'CLICOLOR': '1',\n",
       "        'FORCE_COLOR': '1',\n",
       "        'CLICOLOR_FORCE': '1',\n",
       "        'PAGER': 'cat',\n",
       "        'GIT_PAGER': 'cat',\n",
       "        'MPLBACKEND': 'module://matplotlib_inline.backend_inline'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.environ # environ的全部变量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "861f9b1d",
   "metadata": {},
   "source": [
    "# 模块实践 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b511b79b",
   "metadata": {},
   "source": [
    "## 1.time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "004e6b23",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time # 函数调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b8a78206",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2023, tm_mon=10, tm_mday=30, tm_hour=1, tm_min=33, tm_sec=41, tm_wday=0, tm_yday=303, tm_isdst=0)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# function\n",
    "time.localtime() # 当地时间"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3ff04d9",
   "metadata": {},
   "source": [
    "------\n",
    "* 知识点记录\n",
    "> 1.time.按tab键可以选择全部变量\n",
    ">\n",
    "> 2.help(time)可以查看全部变量功能"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "dbaad3cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7d501c0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.date(2023, 10, 30)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "59462eed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().day\n",
    "# 后面可换成month，year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "eabfb24f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "291236ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "time.sleep(3)\n",
    "print(\"hello world!\")\n",
    "# 三秒后print"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d58f380",
   "metadata": {},
   "source": [
    "# 变量，赋值，数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "cc72864c",
   "metadata": {},
   "outputs": [],
   "source": [
    "dog_name = \"豆豆\" # dog_name为变量名，豆豆是值(被赋予的值)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5af64035",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "豆豆\n"
     ]
    }
   ],
   "source": [
    "print(dog_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "dd15e7ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Zihang Zihang\n",
      "Zichuan Zihang\n"
     ]
    }
   ],
   "source": [
    "# 案例\n",
    "\n",
    "name = \"Zihang\"\n",
    "\n",
    "name2 = name\n",
    "\n",
    "print(name,name2) \n",
    "\n",
    "name = \"Zichuan\" \n",
    "\n",
    "print(name,name2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "85f7e584",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Zihang Zihang\n",
      "Zichuan Zichuan\n"
     ]
    }
   ],
   "source": [
    "# 案例\n",
    "\n",
    "name = \"Zihang\"\n",
    "\n",
    "name2 = name\n",
    "\n",
    "print(name,name2)\n",
    "\n",
    "name = \"Zichuan\"\n",
    "\n",
    "name2 = name\n",
    "\n",
    "print(name,name2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35c5468e",
   "metadata": {},
   "source": [
    "# 改变运行顺序的方法：条件判断if"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6df849d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "尊贵的VVIP用户，您好，登陆成功！\n"
     ]
    }
   ],
   "source": [
    "account = \"zhichao\"\n",
    "if account == account:\n",
    "    print(\"尊贵的VVIP用户，您好，登陆成功！\")\n",
    "else:\n",
    "    print(\"欢迎使用~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "430e8c7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "# 因为我们只对于精确到minute的时间感兴趣，所以我们用“=赋值符”赋right_this_minute这个属性来明确我们的值\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93a76366",
   "metadata": {},
   "source": [
    "# 知识点归纳\n",
    "> 1.=是赋值操作符\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85b3f525",
   "metadata": {},
   "source": [
    "* 书本第18页练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "f2dcaeb9",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'today' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[28], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m today \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSaturday\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m      2\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mParty\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m today \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSunday\u001b[39m\u001b[38;5;124m'\u001b[39m:\n",
      "\u001b[1;31mNameError\u001b[0m: name 'today' is not defined"
     ]
    }
   ],
   "source": [
    "if today == 'Saturday':\n",
    "    print('Party')\n",
    "elif today == 'Sunday':\n",
    "    print('Recover')\n",
    "else:\n",
    "    print('Work, work, work')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "511be628",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'today' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[30], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m today \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSaturday\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m      2\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mParty!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m today \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSunday\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
      "\u001b[1;31mNameError\u001b[0m: name 'today' is not defined"
     ]
    }
   ],
   "source": [
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b174f43",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
